/**
 * Created by Administrator on 2016/4/11.
 */
//入口dao层
var dao = require("./execsql.js");
var msql = require("./../node_modules/mysql");

exports.mianlist=function(req,res){
    var sql="SELECT article_title,image_src,parise_number,post_reason,shop_name,shop_address FROM hc_infomation a1 LEFT JOIN hc_infoimgs_reference a2 ON a1.article_id=a2.article_id JOIN hc_images a3 ON a2.image_id=a3.image_id GROUP BY article_title";
    dao.poolGetConnection(sql,res)
};

exports.mianthelist=function(req,res){

   var pool = msql.createPool({
        connectionLimit: 10,
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'baijie84',
        port: '3306'
    });
    console.log("===============");
    var title = req.query.title;
    var sql="SELECT * FROM hc_infomation a1 LEFT JOIN hc_infoimgs_reference a2 ON a1.article_id=a2.article_id JOIN hc_images a3 ON a2.image_id=a3.image_id LEFT JOIN hc_user a4 ON a4.user_id = a1.user_id WHERE a1.article_title='"+title+"' LIMIT 1";
    //dao.poolGetConnection(sql,res);
    pool.getConnection(function (err, connection) {
        //报错执行 的 代码
        if (err) throw err;
        /*执行sql语句*/
        connection.query(sql, function (err, result) {
            console.log("result" + result);
            /*返回数据*/
            //res.send(result);
            //res.redirect("/pages/mainDetails.html");
            /*链接释放*/    
            connection.release();
        })
    });
};